import { ethers } from 'ethers';
import ABI from '../abis/usdt.json';

import {my_usdt_address} from '@/config/contract'

let provider = new ethers.BrowserProvider(window.ethereum)

// 合约实例
const contract = new ethers.Contract(my_usdt_address, ABI, await provider.getSigner());

export async function balanceOf(
    address) {
    const result = await contract.balanceOf(address);
    return Number(result);
}

// 授权amount的余额给spender
export async function approve(spender, amount) {
    return await contract.approve(spender, amount*10**18);
}

// 查看owner给spender授权的余额
export async function getAllowance(owner, spender) {
    const result = await contract.allowance(owner, spender);
    return Number(result);
}